<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2020/7/13
  Time: 13:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>合同取号</title>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <style>
        /*导航栏*/
        .header{
            width:100%;
            height:45px;
            border-bottom:1px solid #9E9E9E;
            position:fixed;
            top:0px;
            z-index: 100;
            background: #fff;
        }
        .nav{
            overflow:hidden;
        }
        .nav li{
            height:28px;
            line-height:28px;
            float:left;
            font-size:14px;
            margin-left:20px;
            margin-top:6px;
            cursor:pointer;
        }
        .space{
            width:2px;
            margin-left:16px;
        }
        .pad{
            padding:3px 10px;
            line-height:28px;
        }
        .select{
            background-color:#2F8AE3;
            color:#fff;
            border-radius:20px;
            -webkit-border-radius:20px;
            -moz-border-radius:20px;
            -o-border-radius:20px;;
            -ms-border-radius:20px;
        }
        .tableTitle span{
            font-size:22px;
            color:#494d59;
            padding-left:20px;
        }
        .content{
            width: 50%;
            border: 1px solid #9E9E9E;
            padding: 20px;
            margin: 0 auto;
            margin-top: 20px;
        }
        .layui-form{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .btn{
            margin-top: 10px;
        }
        .btn>button{
            background: #2F8AE3;
            border-radius: 6px;
        }
        #duplication{
            cursor: not-allowed;
        }
    </style>
</head>
<body>
<%--合同取号--%>
<div style="height: 45px;">
    <div class="header">
        <ul class="nav">
            <li>
                <span class="select pad zhu">主合同取号</span>
                <img class="space" src="../../img/twoth.png" alt="">
            </li>
            <li>
                <span class="pad fen" style="line-height: 32px;">分包合同取号</span>
                <img class="space bgcolor" src="../../img/twoth.png" alt="">
            </li>
            <li>
                <span class="pad erweima" style="line-height: 32px;">二维码取号</span>
            </li>
        </ul>
    </div>
</div>

<div class="list">
    <div class="content query">
        <form class="layui-form" action="" lay-filter="example" class="ajaxform">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 90px;margin-left:-10px"><span style="color: red;">*</span>主合同名称：</label>
                    <div class="layui-input-inline" style="width: 250px;margin-right: -10px;">
                        <input type="text"  name="contractName" lay-verify="required|phone" autocomplete="off" class="layui-input contractName">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>承包单位：</label>
                <div class="layui-input-block" style="width: 250px;">
                    <select name="contractor" lay-verify="required" class="contractor">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>业务分类：</label>
                <div class="layui-input-block" style="width: 250px;">
                    <select name="codeName" lay-verify="required" class="codeName">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号预览：</label>
                    <div class="layui-input-inline" style="width: 250px;margin-right: -10px;">
                        <input type="text" layer3="yvlan" id="duplication"  class="layui-input" disabled>
                    </div>
                </div>
            </div>
            <div class="btn">
                <button type="button"  class="layui-btn layui-btn-normal" id="duplication2"  readonly="readonly" layer1="qunding" >确认编号</button>
                <button type="button" class="layui-btn layui-btn-normal clear" layer2="qunding" >重新编号</button>
            </div>
        </form>
    </div>
</div>

<div class="list2" style="display: none;">
    <div class="content query2">
        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label" style="margin-left: -13px;width:90px"><span style="color: red;">*</span>主合同：</label>
                <div class="layui-input-block" style="width: 250px;">
                    <select name="contractor" lay-verify="required" class="masterContract">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label"  style="width: 105px;margin-left: -4px;"><span style="color: red;">*</span>分包合同名称：</label>
                    <div class="layui-input-inline"  style="width: 250px;">
                        <input type="text"  name="contractName" lay-verify="required|phone" autocomplete="off" class="layui-input" id="contract">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red;">*</span>承包单位：</label>
                <div class="layui-input-block" style="width: 250px;">
                    <select name="contractor" lay-verify="required" class="fencontractor">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号预览：</label>
                    <div class="layui-input-inline" style="width: 250px;margin-right: -10px;">
                        <input type="text" name="lv2" disabled  class="layui-input look">
                    </div>
                </div>
            </div>
            <div class="btn">
                <button type="button" class="layui-btn layui-btn-normal determined">确认编号</button>
                <button type="button" class="layui-btn layui-btn-normal renumber">重新编号</button>
            </div>
        </form>
    </div>
</div>

<div class="list3" style="display: none; text-align: center; background-color: #ffffff; height: 94%;">
    <div style="padding-top: 4%;">
        <h1 style="font-size: 37px; color: rgb(0, 49, 122);">合同取号二维码</h1>
        <img src="/img/ContractNo/contracterweima.png" />
        <h1 style="font-size: 37px; color: rgb(0, 49, 122);">海马移动平台</h1>
    </div>
</div>

</body>
</html>
<script>
    $(function () {
        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) || /(Android)/i.test(navigator.userAgent)) {
            window.location.replace('/ContractNoView/H5takeNumber');
        }
        //判断二维码显示隐藏
        $.ajax({
            url:'/syspara/selectTheSysPara',
            dataType:'json',
            type:'get',
            data:{
                paraName:'MYPROJECT',
            },
            success:function (res) {
                if(res.object[0].paraValue === 'COESOA'){
                    $('.erweima').show()
                    $('.bgcolor').show()
                }else{
                    $('.erweima').hide()
                    $('.bgcolor').hide()
                }
            }
        })
    })


    //地址栏取参
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);

        if (r != null) {
            return unescape(r[2]);
        } else {
            return null;
        }
    }
    var display = GetQueryString('display');

    //合同管理需要调用所以隐藏按钮
    if (display == 'none'){
        $('#duplication2').hide();
        $('.clear').hide();

        $('.determined').hide();
        $('.renumber').hide();
    }

    $('.header').on('click','li',function(){
        $('.header span').removeClass('select')
        $(this).find('span').addClass('select');
    })

    //页签切换
    $('.zhu').click(function(){
        $('.list2').hide()
        $('.list3').hide()
        $('.list').show()

        $('#duplication2').attr("layer1","qunding");
        $('.clear').attr("layer2","qunding");
        $('#duplication').attr("layer3","yvlan");


        $('.determined').attr("layer1","");
        $('.renumber').attr("layer2","");
        $('input[name="lv2"]').attr("layer3","");


    })
    $('.fen').click(function(){
        $('.list2').show()
        $('.list').hide()
        $('.list3').hide()

        $('#duplication2').attr("layer1","");
        $('.clear').attr("layer2","");
        $('#duplication').attr("layer3","");


        $('.determined').attr("layer1","qunding");
        $('.renumber').attr("layer2","qunding");
        $('input[name="lv2"]').attr("layer3","yvlan");

    })
    $('.erweima').click(function(){
        $('.list3').show()
        $('.list').hide()
        $('.list2').hide()
    })

    var form,layer;
    $(function(){

        //判断是否需要是OA系统用户


        layui.use(['form','layer'], function() {
            form = layui.form
                ,layer=layui.layer;

            //承包单位
            $.ajax({
                url:'/code/getCode',
                dataType:'json',
                type:'get',
                data:{
                    parentNo:'CONTRACT_UNIT',
                },
                success:function(res){
                    var obj = res.obj
                    var str = ''
                    for (var i = 0; i < obj.length; i++) {
                        str += '<option value="' + obj[i].codeNo + '">' + obj[i].codeName + '</option>'
                    }
                    $('.fencontractor').append(str)
                    form.render('select');
                }
            })

            //承包单位
            $.ajax({
                url:'/code/getCode',
                dataType:'json',
                type:'get',
                data:{
                    parentNo:'CONTRACT_UNIT',
                },
                success:function(res){
                    var obj = res.obj
                    var str = ''
                    for (var i = 0; i < obj.length; i++) {
                        str += '<option value="' + obj[i].codeNo + '">' + obj[i].codeName + '</option>'
                    }
                    $('.contractor').append(str)
                    form.render('select');
                }
            })

            //业务分类
            $.ajax({
                url:'/code/getCode',
                dataType:'json',
                type:'get',
                data:{
                    parentNo:'BUSINESS_TYPE_CODE',
                },
                success:function(res){
                    var obj = res.obj
                    var str = ''
                    for (var i = 0; i < obj.length; i++) {
                        str += '<option value="' + obj[i].codeNo + '">' + obj[i].codeName + '</option>'
                    }
                    $('.codeName').append(str)
                    form.render('select');
                }
            })

            //主合同取号确认并复制编号
            $('#duplication2').click(function () {
                if($('.contractName').val()==""){
                    layer.msg('请填写合同名称', {icon: 2});
                    return false
                }
                if($('.contractor').val()==""){
                    layer.msg('请填写承包单位', {icon: 2});
                    return false
                }
                if($('.codeName').val()==""){
                    layer.msg('请填写业务分类', {icon: 2});
                    return false
                }
                $.ajax({
                    url:'/ContractNo/insertContractNo',
                    dataType:'json',
                    type:'get',
                    data:{
                        contractType:1,
                        contractName:$('.contractName').val(),
                        doUnit:$('.contractor').val(),
                        do2Unit:$('.contractor').val(),
                        businessType:$('.codeName').val(),
                        unitType:1
                    },
                    success:function(res){
                        $('#duplication').val(res.object)
                        $('.query input').attr('disabled','disabled')
                        $('.query select').attr('disabled','disabled')
                        form.render('select');
                    }
                })
            })

            //主合同取号的重新编号
            $('.clear').click(function () {
                $.ajax({
                    url:'/ContractNo/delContractNo',
                    dataType:'json',
                    type:'get',
                    data:{
                        unitType:1,
                        contractNo:$('#duplication').val()
                    },
                    success:function(res){
                        $('.query select').val('')
                        $('.query input').val('')
                        $('.query select').removeAttr('disabled')
                        $('.contractName').removeAttr('disabled')
                        form.render('select');
                    }
                })
            })

            //主合同名称的接口
            $.ajax({
                url:'/ContractNo/findContractNo?contractType=1',
                dataType:'json',
                type:'get',
                success:function(res){
                    var obj = res.obj
                    var str = ''
                    for (var i = 0; i < obj.length; i++) {
                        str += '<option value="' + obj[i].contractId + '" contractNo ="'+obj[i].contractNo+'">' + obj[i].contractName + '</option>'
                    }
                    $('.masterContract').append(str)
                    form.render('select');
                }
            })

            //分包合同区号-并复制编号
            $('.determined').click(function(){
                if($('.masterContract').val()==""){
                    layer.msg('请填写主合同名称', {icon: 2});
                    return false
                }
                if($('#contract').val()==""){
                    layer.msg('请填写分包合同名称', {icon: 2});
                    return false
                }
                if($('.fencontractor').val()==""){
                    layer.msg('请填写承包单位', {icon: 2});
                    return false
                }
                $.ajax({
                    url:'/ContractNo/insertContractNo',
                    dataType:'json',
                    type:'get',
                    data:{
                        contractType:2,
                        do2Unit:$('.fencontractor').val(),
                        unitCode:$('.fencontractor').val(),
                        contractId:$('.masterContract').val(),
                        contractName:$('#contract').val(),
                        mainContractNos:$('.masterContract option:selected').attr('contractno'),
                        unitType:2
                    },
                    success:function(res){
                        $('.look').val(res.object)
                        $('.query2 input').attr('disabled','disabled')
                        $('.query2 select').attr('disabled','disabled')
                        form.render('select');
                    }
                })
            })

            //分包合同区号-重新编号
            $('.renumber').click(function(){
                $.ajax({
                    url:'/ContractNo/delContractNo',
                    dataType:'json',
                    type:'get',
                    data:{
                        unitType:2,
                        contractNo:$('#contract').val(),
                        unitCode:$('.fencontractor').val(),
                        mainContractNos:$('.masterContract option:selected').attr('contractno')
                    },
                    success:function(res){
                        $('.query2 select').val('')
                        $('.query2 input').val('')
                        $('.query2 select').removeAttr('disabled')
                        $('#contract').removeAttr('disabled')
                        form.render('select');
                    }
                })
            })



        })
    })




    function queding() {
        var yvlan = $('input[layer3="yvlan"]').val();
        $('input[name="contractNo"]', parent.document).val(yvlan);
        parent.close();
    }
</script>
